<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!--数据格式化标签库-->
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="<%=basePath%>/static/js/jquery-3.3.1.js"></script>
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>/static/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>/static/css/basic.css">
<script src="<%=basePath%>/static/js/bootstrap.min.js"></script>
<style type="text/css">
.table>thead>tr>th {
	padding: 13px 2px 10px;
}

.table-bordered>thead>tr>th {
	border-bottom-width: 0
}

.white_content {
	text-align: center;
	display: none;
	position: absolute;
	top: 35%;
	left: 37%;
	width: 30%;
	height: auto;
	padding: 55px;
	/* border: 1px solid gray; */
	background-color: white;
	z-index: 1002;
	overflow: auto;
	border-radius: 8px
}

.black_overlay {
	display: none;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.3);
	z-index: 1001;
	filter: alpha(opacity = 88);
}
</style>
<script type="text/javascript">
	$(function () {
		$(".btn-return").on("click",function(){
			let index = $(".btn-return").index($(this));
			console.log('index: ', index)
			let $time = $("#time");
			let time = 3;
			$("#return-warn").hide().fadeIn(600)
			.css("display", "block");
			$("#fade").hide().fadeIn(600).css("display", "block");
			let timer =setInterval(() => {
				if(time <= 1) {
					clearInterval(timer);
					let borrowId = $(".borrowId").eq(index);
					console.log('borrowId: ', borrowId);
					let isbn = $(".isbn").eq(index);
					let message = {
							"borrowId" : borrowId.text(),
							   "isbn"  : isbn.text()
					}
					console.log(message)
					$.ajax({
						url:"<%=path%>/bookreturn",
						type:"post",
						data:message,
						success:function(){
							window.location.reload();
						},
						error:function(){
							console.log(7777777);
						}
					})
				}
				time --;
				$time.text(time);
			}, 1000)
		})
		
		$(".btn-borrow").on("click",function(){
			let index = $(".btn-borrow").index($(this));
			let $time = $("#time1");
			let time = 3;
			$("#borrow-warn").hide().fadeIn(600)
			.css("display", "block");
			$("#fade").hide().fadeIn(600).css("display", "block");
			let timer =setInterval(() => {
				if(time <= 1) {
					clearInterval(timer);
					let borrowId = $(".borrowId").eq(index);
					let message = {
							"borrowId" : borrowId.text()
					}
					console.log(message)
					$.ajax({
						url:"<%=path%>/borrowagain",
						type:"post",
						data:message,
						success:function(data){
							console.log(data)
							if(data.result==true){
							window.location.reload();
							}
							if(data.result==false){
								$("#borrow-warn").hide().fadeIn(600)
								.css("display", "none");
								$("#erorr-warn").hide().fadeIn(600)
								.css("display", "block");
							}
						},
						error:function(){
							console.log(7777777);
						}
					})
				}
				time --;
				$time.text(time);
			}, 1000)
		})
		
		
		$(".closeBtn").on("click", function() {
			$("#fade").fadeOut(600).hide(300);
			$("#erorr-warn").fadeOut(600).hide(300);

		});
	})
</script>
</head>
<body>
	<!--头部-->
	<nav class="navbar navbar-inverse navbar-fixed-top">
		<div class="container-fluid">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
					aria-expanded="false">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="javascript:;">欢迎来到图书管理系统</a>
			</div>

			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse"
				id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav navbar-right">
					<!--<li><a href="javascript:;" class="btn btn-default btn-login">登录</a></li>-->
					<li class="dropdown" style="margin-top: 5px;"><a href="#"
						class="dropdown-toggle" data-toggle="dropdown" role="button"
						aria-haspopup="true" aria-expanded="false"> <span
							class="glyphicon glyphicon-user"></span> 欢迎您，${reader.name }<span
							class="caret"></span></a>
						<ul class="dropdown-menu" style="margin-top: 2px">
							<li><a href="<%=path%>/">退出</a></li>
						</ul></li>
				</ul>
			</div>
			<!-- /.navbar-collapse -->
		</div>
		<!-- /.container-fluid -->
	</nav>

	<!--主体-->
	<div class="container-fluid" id="main">
		<div class="row">
			<div class="col-md-2 left-content">
				<div class="aside-nav">
					<ul class="list-group aside-nav-list">
						<li class="list-group-item "><a
							href="<%=path%>/reader/books/1">图书查询 <span
								class="pull-right glyphicon glyphicon-chevron-right"></span>
						</a></li>
						<li class="list-group-item active"><a
							href="<%=path%>/reader/borrow/1">借阅信息 <span
								class="pull-right glyphicon glyphicon-chevron-right"></span>
						</a></li>
						<li class="list-group-item "><a
							href="<%=path%>/reader/overdue/1">逾期信息 <span
								class="pull-right glyphicon glyphicon-chevron-right"></span>
						</a></li>
						<li class="list-group-item "><a
							href="<%=path%>/lesson/reader/chooseTest">在线考试 <span
								class="pull-right glyphicon glyphicon-chevron-right"></span>
						</a></li>
					</ul>
				</div>
			</div>
			<div class="col-md-10 right-content">
				<div class="section-wrap">
					<div class="wrap-top">
						<div class="panel panel-default">
							<div class="panel-heading">借阅查询</div>
							<div class="panel-body">
								<form class="form-horizontal"
									action="<%=path%>/reader/borrow/select" method="post">
									<label for="borrowId" class="col-sm-2 control-label text-right">借阅编号</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="borrowId"
											name="borrowId" placeholder="请输入借阅编号">
									</div>
									<label for="isbn" class="col-sm-2 control-label text-right">图书ISBN号</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="isbn" name="isbn"
											placeholder="请输入归还图书的ISBN号">
									</div>
									<div
										class="form-group col-md-2 col-xs-2 col-xs-offset-2 last-form-group">
										<button class="btn btn-default btn-primary" type="submit">查询</button>
									</div>
								</form>
							</div>
						</div>
					</div>
					<div class="wrap-bottom">
						<table class="table table-bordered">
							<thead>
								<tr>
									<th>借阅编号</th>
									<th>图书ISBN号</th>
									<th>图书名称</th>
									<th>读者证件</th>
									<th>读者名称</th>
									<th>借书日期</th>
									<th>归还日期</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="borrows" items="${bean.list}">
									<tr>
										<td class="borrowId">${borrows.borrowId }</td>
										<td class="isbn">${borrows.isbn }</td>
										<td>${borrows.bookName }</td>
										<td>${borrows.libCardId }</td>
										<td>${borrows.name }</td>
										<td><fmt:formatDate value="${borrows.borrowDate }"
												type="date" pattern="yyyy-MM-dd HH:mm:ss" /></td>
										<td><fmt:formatDate value="${borrows.endDate }"
												type="date" pattern="yyyy-MM-dd HH:mm:ss" /></td>
										<td><button type="button"
												class="btn btn-info btn-xs  btn-return"
												style="margin-right: 4px">还书</button>
											<button type="button"
												class="btn btn-danger btn-xs btn-borrow">续借</button></td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
					<div class="page-nav text-right">
						<nav aria-label="Page navigation">
							<ul class="pagination">
								<c:if test="${bean.totalPage!=0}">
									<li><a href="#">第${bean.pageNum}页/共${bean.totalPage}页</a></li>
									<c:if test="${select==false }">
										<li><a href="<%=path%>/reader/borrow/1">首页</a></li>
									</c:if>
									<c:if test="${select==true }">
										<li><a href="#">首页</a></li>
									</c:if>
									<%--如果当前为第一页时,就没有上一页这个超链接显示 --%>
									<c:if test="${bean.pageNum==1}">
										<c:forEach begin="${bean.start }" end="${bean.end }" step="1"
											var="i">
											<c:if test="${bean.pageNum ==i}">
												<li><a href="#">${i}</a></li>
											</c:if>
											<c:if test="${bean.pageNum !=i}">
												<c:if test="${select==false }">
													<li><a href="<%=path %>/reader/borrow/${i}">${i}</a></li>
												</c:if>
												<c:if test="${select==true }">
													<li><a href="<%=path %>/reader/borrow/select/${i}">${i}</a></li>
												</c:if>
											</c:if>
										</c:forEach>
										<c:if test="${bean.totalPage!=1}">
											<c:if test="${select==false }">
												<li><a
													href="<%=path %>/reader/borrow/${bean.pageNum+1}"
													aria-label="Next"> <span aria-hidden="true">&raquo;</span>
												</a></li>
											</c:if>
											<c:if test="${select==true }">
												<li><a
													href="<%=path %>/reader/borrow/select/${bean.pageNum+1}"
													aria-label="Next"> <span aria-hidden="true">&raquo;</span>
												</a></li>
											</c:if>
										</c:if>
									</c:if>
									<%--如果当前页不是第一页也不是最后一页,则有上一页和下一页 这个超链接的显示--%>
									<c:if
										test="${bean.pageNum >1 && bean.pageNum < bean.totalPage}">
										<c:if test="${select==false }">
											<li><a href="<%=path %>/reader/borrow/${bean.pageNum-1}"
												aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
											</a></li>
										</c:if>
										<c:if test="${select==true }">
											<li><a
												href="<%=path %>/reader/borrow/select/${bean.pageNum-1}"
												aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
											</a></li>
										</c:if>
										<c:forEach begin="${bean.start }" end="${bean.end }" step="1"
											var="i">

											<c:if test="${bean.pageNum == i }">
												<li><a href="#">${i }</a></li>
											</c:if>
											<c:if test="${bean.pageNum != i }">
												<c:if test="${select==false }">
													<li><a href="<%=path %>/reader/borrow/${i}">${i}</a></li>
												</c:if>
												<c:if test="${select==true }">
													<li><a href="<%=path %>/reader/borrow/select/${i}">${i}</a></li>
												</c:if>
											</c:if>
										</c:forEach>
										<c:if test="${select==false }">
											<li><a href="<%=path %>/reader/borrow/${bean.pageNum+1}"
												aria-label="Next"> <span aria-hidden="true">&raquo;</span>
											</a></li>
										</c:if>
										<c:if test="${select==true }">
											<li><a
												href="<%=path %>/reader/borrow/select/${bean.pageNum+1}"
												aria-label="Next"> <span aria-hidden="true">&raquo;</span>
											</a></li>
										</c:if>
									</c:if>
									<%--如果当前页是最后一页,则只有上一页这个超链接显示,下一页没有 --%>
									<c:if
										test="${bean.pageNum ==  bean.totalPage && bean.pageNum!=1}">
										<c:if test="${select==false }">
											<li><a href="<%=path %>/reader/borrow/${bean.pageNum-1}"
												aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
											</a></li>
										</c:if>
										<c:if test="${select==true }">
											<li><a
												href="<%=path %>/reader/borrow/select/${bean.pageNum-1}"
												aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
											</a></li>
										</c:if>
										<c:forEach begin="${bean.start }" end="${bean.end }" step="1"
											var="i">

											<c:if test="${bean.pageNum == i }">
												<li><a href="#">${i }</a></li>
											</c:if>
											<c:if test="${bean.pageNum != i }">
												<c:if test="${select==false }">
													<li><a href="<%=path %>/reader/borrow/${i}">${i}</a></li>
												</c:if>
												<c:if test="${select==true }">
													<li><a href="<%=path %>/reader/borrow/select/${i}">${i}</a></li>
												</c:if>
											</c:if>
										</c:forEach>
									</c:if>
									<c:if test="${select==false }">
										<li><a href="<%=path %>/reader/borrow/${bean.totalPage }">尾页</a></li>
									</c:if>
									<c:if test="${select==true }">
										<li><a href="#">尾页</a></li>
									</c:if>
								</c:if>
							</ul>
						</nav>
					</div>
				</div>
			</div>
		</div>
	</div>


	<div id="return-warn" class="white_content">
		<span style="font-size: 25px;" class="text-success">还书成功</span>
		<p id="time" class="text-muted"
			style="font-size: 20px; margin-top: 15px">3</p>
	</div>

	<div id="borrow-warn" class="white_content">
		<span style="font-size: 25px;" class="text-success">处理中...</span>
		<p id="time1" class="text-muted"
			style="font-size: 20px; margin-top: 15px">3</p>
	</div>

	<div id="erorr-warn" class="white_content">
		<button type="button" class="close closeBtn" data-dismiss="modal"
			aria-label="Close">
			<span aria-hidden="true"
				style="position: absolute; margin-top: -35px; margin-left: 23px">×</span>
		</button>
		<span style="font-size: 25px;" class="text-danger">你已经续借过一次了</span>
	</div>

	<div id="fade" class="modal black_overlay"></div>
</body>
</html>